Skip to content

[SPARK-57271][PYTHON] Propagate traceback locals to Python planner runner - #57509

Closed
linhongliu-db wants to merge 1 commit into
apache:masterfrom
linhongliu-db:task/oss-spark-spark-57271-pythonplannerrunner-which-doesn-t-extend-basepythonrunner-f822ad87ff/implementation
Closed

[SPARK-57271][PYTHON] Propagate traceback locals to Python planner runner#57509
linhongliu-db wants to merge 1 commit into
apache:masterfrom
linhongliu-db:task/oss-spark-spark-57271-pythonplannerrunner-which-doesn-t-extend-basepythonrunner-f822ad87ff/implementation

Conversation

@linhongliu-db

@linhongliu-db linhongliu-db commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR propagates SPARK_TRACEBACK_WITH_LOCALS from PythonPlannerRunner when spark.sql.execution.pyspark.udf.tracebackWithLocals.enabled is enabled.

It also adds a UDTF analyze regression test that raises from the planner-side Python worker and verifies the surfaced traceback includes the local variable.

Why are the changes needed?

PythonPlannerRunner already reads spark.sql.execution.pyspark.udf.tracebackWithLocals.enabled, but it did not add SPARK_TRACEBACK_WITH_LOCALS to the Python worker environment. As a result, planner-driven Python paths such as UDTF analyze did not honor the traceback-locals config, unlike regular Python UDF execution.

Does this PR introduce any user-facing change?

Yes. When spark.sql.execution.pyspark.udf.tracebackWithLocals.enabled is enabled, Python exceptions raised through planner-driven Python paths can now include local variables in their tracebacks.

How was this patch tested?

Passed:

python3 python/run-tests.py --testnames "pyspark.sql.tests.test_udtf UDTFTests.test_udtf_analyze_traceback_with_locals"
python3 python/run-tests.py --testnames "pyspark.sql.tests.test_udf UDFTests.test_udf_traceback_with_locals"

Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex (GPT-5)

@linhongliu-db
linhongliu-db marked this pull request as ready for review July 27, 2026 20:28

@cloud-fan cloud-fan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 blocking, 0 non-blocking, 0 nits.
The implementation is consistent with the existing Python worker contract and the regression test covers the affected end-to-end path.

Verification

I traced the SQL config read through PythonPlannerRunner.runInPython to the worker environment and compared it with BasePythonRunner, which uses the same conditional environment variable. Python's shared handle_worker_exception consumes that variable as the TracebackException.capture_locals switch, and the new UDTF test exercises the planner-worker exception path.

@cloud-fan cloud-fan closed this in 87dbc24 Jul 29, 2026
cloud-fan pushed a commit that referenced this pull request Jul 29, 2026
…nner

### What changes were proposed in this pull request?

This PR propagates `SPARK_TRACEBACK_WITH_LOCALS` from `PythonPlannerRunner` when `spark.sql.execution.pyspark.udf.tracebackWithLocals.enabled` is enabled.

It also adds a UDTF `analyze` regression test that raises from the planner-side Python worker and verifies the surfaced traceback includes the local variable.

### Why are the changes needed?

`PythonPlannerRunner` already reads `spark.sql.execution.pyspark.udf.tracebackWithLocals.enabled`, but it did not add `SPARK_TRACEBACK_WITH_LOCALS` to the Python worker environment. As a result, planner-driven Python paths such as UDTF `analyze` did not honor the traceback-locals config, unlike regular Python UDF execution.

### Does this PR introduce _any_ user-facing change?

Yes. When `spark.sql.execution.pyspark.udf.tracebackWithLocals.enabled` is enabled, Python exceptions raised through planner-driven Python paths can now include local variables in their tracebacks.

### How was this patch tested?

Passed:

```
python3 python/run-tests.py --testnames "pyspark.sql.tests.test_udtf UDTFTests.test_udtf_analyze_traceback_with_locals"
python3 python/run-tests.py --testnames "pyspark.sql.tests.test_udf UDFTests.test_udf_traceback_with_locals"
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex (GPT-5)

Closes #57509 from linhongliu-db/task/oss-spark-spark-57271-pythonplannerrunner-which-doesn-t-extend-basepythonrunner-f822ad87ff/implementation.

Authored-by: Linhong Liu <linhong.liu@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 87dbc24)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@cloud-fan

Copy link
Copy Markdown
Contributor

thanks, merging to master/4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants